Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Add layer: tf.layers.dot #330

Merged
merged 13 commits into from
Oct 4, 2018
Merged

Add layer: tf.layers.dot #330

merged 13 commits into from
Oct 4, 2018

Conversation

caisq
Copy link
Contributor

@caisq caisq commented Sep 28, 2018

FEATURE

Fixes tensorflow/tfjs#218


This change is Reviewable

@caisq caisq changed the title [WIP]: Add layer: tf.layers.dot Add layer: tf.layers.dot Sep 30, 2018
Copy link
Contributor

@bileschi bileschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo adding a check for 4D tensors, as discussed offline.

normalize?: boolean;
}

function normalizeAxis(axis: number, dim: number): number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function gets a positive axis index from a negative one, right? There is a bit of a name collision here with the concept above of 'normlize' meaning l2 normalization. Can we rename this internal function or give a short docstring describing the purpose?

}

function normalizeAxis(axis: number, dim: number): number {
while (axis < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems possible that this results in an infinite loop if the user tries to dot product a scalar. Can we throw an error message instead?

return axis;
}

function batchDot(x: Tensor, y: Tensor, axes: number|number[]): Tensor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should axes type here be number|[number]|[number,number] ? I.e., should lists of length greater than 2 be disallowed?

Copy link
Contributor Author

@caisq caisq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @caisq, @bileschi, and @nsthorat)


src/layers/merge.ts, line 902 at r1 (raw file):

Previously, bileschi (Stanley Bileschi) wrote…

This function gets a positive axis index from a negative one, right? There is a bit of a name collision here with the concept above of 'normlize' meaning l2 normalization. Can we rename this internal function or give a short docstring describing the purpose?

This method mainly deals with negative axis indices such as -1 and -2. Renamed to interperableAxis and added a doc string.


src/layers/merge.ts, line 903 at r1 (raw file):

Previously, bileschi (Stanley Bileschi) wrote…

Also, it seems possible that this results in an infinite loop if the user tries to dot product a scalar. Can we throw an error message instead?

Good point. Added assertion for rank >= 2 in both x and y.


src/layers/merge.ts, line 909 at r1 (raw file):

Previously, bileschi (Stanley Bileschi) wrote…

should axes type here be number|[number]|[number,number] ? I.e., should lists of length greater than 2 be disallowed?

Done.

@bileschi
Copy link
Contributor

bileschi commented Oct 4, 2018

:!LGTM:

@caisq caisq merged commit 9bed915 into tensorflow:master Oct 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants